<template>
  <div class="xisha_1">
    <div class="content_title" v-if="!inline" @click="showDialogBig('xishaDialogBig')">
      <span @click="showDialogTech" style="cursor:pointer">
        <span class="content_text">细纱</span>
        <img class="content_img" src="../assets/img/resource/icon/xisha.png" alt="" srcset="" />
      </span>
    </div>
    <div class="xisha_body">
      <div class="xisha_row1">
        <div class="item" v-for="(item, index) in xishaData.xishaRow1Data" :key="index + 'l'">
          <div v-if="index == 4 || index == 9 || index == 14 || index == 19">
            <div class="dongli" @click="clickHandleDl('xiSha1_' + index)">
              <img src="../assets/img/dongli.svg" alt="" srcset="" />
            </div>
          </div>
          <!-- 弹框内的细砂不展示温度 -->
          <div v-if="index == 13 && !inline">
            <div class="wendu">
              <img src="../assets/img/wendu.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item" :inline="inline"></xisha>
          </div>
        </div>
      </div>
    </div>
    <xishaDialog ref="xishaDialog" />
    <xishaDialogBig ref="xishaDialogBig" />
    <!-- 动力柜弹窗控件 -->
    <dongliDialog ref="dongliDialog"></dongliDialog>
    <!-- 细砂工艺详情 -->
    <xisha-dialog-tech v-if="techShow" ref="xishaDialogTech"></xisha-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from "../views/qcs/components/dialog/dialog_dongli/index";
import xisha from "../views/qcs/components/xisha";
import xishaDialog from "../views/qcs/components/dialog/dialog_xisha/index";
import xishaDialogBig from "../views/qcs/components/dialogBig/dialog_xisha/index";
import COMMON from "../utils/common";
import dongLiMenu from "@/assets/data/dongli.json";
import dongliItem from "@/assets/data/dongliItem.json";
export default {
  name: "XiSha",
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: true,
      xishaData: {
        // 148-176
        xishaRow1Data: []
      },
      dongLiMenu: {},
      dongLiItem: {},
      xishaDialog: false,
      techShow: false
    };
  },
  components: {
    dongliDialog,
    xisha,
    xishaDialog,
    xishaDialogBig
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.xishaDialogTech = require("../views/qcs/components/dialogBig/dialog_xisha_tech/index").default;
  },
  created() {
    this.dongLiMenu = dongLiMenu;
    this.dongLiItem = dongliItem;
  },
  computed: {
    xiShaGroupState() {
      return this.$store.state.xiShaGroupState;
    }
  },
  watch: {
    xiShaGroupState: {
      immediate: true,
      handler(val) {
        this.xishaData.xishaRow1Data = COMMON.devSnFilter(val.data, 148, 176);
      }
    }
  },
  methods: {
    closeHandle(type) {
      // 若细砂组件在1.5级弹窗内，当关闭二级弹窗时，需要打开1.5级的轮询
      if (this.inline) {
        // 关闭二级轮询
        this.$EventBus.$emit("clearTypeInterval", type);
        this.$parent.$parent.getTableData();
      } else {
        this.$parent.closeParentHandle();
      }
    },
    showDialogBig(flag) {
      console.log("flag", flag);
      // this.$parent.getInfoByDevSn("XISHA", item.devSn);
      // this.$refs.xishaDialog.showDialog(item);
    },
    clickHandle(item) {
      // this.$store.commit('optNewestDevSn', item)
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "XISHA", item.devSn);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("XISHA", item.devSn);
      }
      this.$refs.xishaDialog.showDialog(item);
    },
    clickHandleDl(item) {
      var getInfoQuary = this.dongLiMenu[item];
      var dialogData = this.dongLiItem[item];
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "DONGLI", getInfoQuary);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("DONGLI", getInfoQuary);
      }
      this.$refs.dongliDialog.showDialog(dialogData);
    },
    showDialogTech() {
      this.techShow = true;
      this.$nextTick(() => {
        setTimeout(() => {
          // 初始化请求
          // 1.5级轮询
          this.$parent.openInlineDialog("XISHA", { start: 1, end: 176 });
          this.$refs.xishaDialogTech.showDialog();
        });
      });
    },
    closeDialogTech() {
      this.techShow = false;
      this.$parent.closeParentHandle();
    }
  }
};
</script>

<style scoped></style>
